var proveedores = {
		init:function(){
			var anterior_id;
			var proveedor = this;
			$('#proveedores').jqGrid({
	           url:'proveedores/index',
	           datatype:'json',
	           mtype:'POST',
			   colNames:['id','Codigo','Razon Social','Nombre Comercial','Direccion','Ruc','DNI','Fecha Inicio','Telefono','Fax'
			   				,'Email','Localidad','Apellido Paterno', 'Apellido Materno','Nombre(s)','Pagina Web','Rubro','Creado','Estado'
						],
	           colModel:[
				   {name:"data[Proveedor][id]",hidden:true},
	               {name:"data[Proveedor][codigo]",index:'Proveedor.codigo',width:34,align:"right",sortable:true,editable:true,editoptions:{size:15,required:true, maxlength:5},editrules:{required:true,number:true,siza:5},searchoptions:{sopt:['cn','eq','ne','lt','le','gt','ge','bw','ew']}},
				   {name:"data[Proveedor][razonsocial]",index:'Proveedor.razonsocial',sortable:true,editable:true,editoptions:{size:35, required:true, maxlength:255},editrules:{required:true},searchoptions:{sopt:['cn','eq','ne','lt','le','gt','ge','bw','ew']}},
	               {name:"data[Proveedor][nombrecomercial]",index:'Proveedor.nombrecomercial',hidden:true,editable:true,editoptions:{size:35, maxlength:255},editrules:{edithidden:true, required:true}},
				   {name:"data[Proveedor][direccion]",index:'Proveedor.direccion',sortable:true,editable:true,editoptions:{size:35, maxlength:255},editrules:{required:true},searchoptions:{sopt:['cn','eq','ne','lt','le','gt','ge','bw','ew']}},
	               {name:"data[Proveedor][ruc]",index:'Proveedor.ruc',width:65,sortable:true,editable:true,editoptions:{size:15, maxlength:11},editrules:{number:true,required:true, number:true},searchoptions:{sopt:['cn','eq','ne','lt','le','gt','ge','bw','ew']}},
				   {name:"data[Proveedor][dni]",index:'Proveedor.dni',width:25,hidden:true,editable:true,editoptions:{size:15, maxlength:8},editrules:{edithidden:true,number:true}},
				   {name:"data[Proveedor][fechainicio]",index:'Proveedor.fechainicio',hidden:true,editoptions:{size:15, maxlength:10},editable:true,sorttype:"date",editrules:{edithidden:true,date:true,required:false}},
				   {name:"data[Proveedor][telefono]",width:48,index:'Proveedor.telefono',sortable:true,editable:true,editoptions:{size:20, maxlength:12},editrules:{number:true},searchoptions:{sopt:['cn','eq','ne','lt','le','gt','ge','bw','ew']}},
				   {name:"data[Proveedor][fax]",index:'Proveedor.fax',hidden:true,editable:true,editoptions:{size:20, maxlength:12}, editrules:{edithidden:true,number:true}},
				   {name:"data[Proveedor][email]",index:'Proveedor.email',hidden:true,editable:true,editoptions:{size:35},editrules:{edithidden:true,email:true,required:false}},
				   {name:"data[Proveedor][localidad]",index:'Proveedor.localidad',hidden:true,editable:true,editoptions:{size:35, maxlength:255},editrules:{edithidden:true}},
				   {name:"data[Proveedor][appaterno]",index:'Proveedor.appaterno',hidden:true,editable:true,editoptions:{size:20, maxlength:20},editrules:{edithidden:true}},
				   {name:"data[Proveedor][apmaterno]",index:'Proveedor.apmaterno',hidden:true,editable:true,editoptions:{size:20, maxlength:20},editrules:{edithidden:true}},
				   {name:"data[Proveedor][nombres]",index:'Proveedor.nombres',hidden:true,editable:true,editoptions:{size:35,maxlength:60},editrules:{edithidden:true}},
				   {name:"data[Proveedor][paginaweb]",index:'Proveedor.paginaweb',hidden:true,editable:true,editoptions:{size:35,maxlength:250},editrules:{edithidden:true,url:true,required:false}},
				   {name:"data[Proveedor][rubro]",index:'Proveedor.rubro',width:60,align:'left',sortable:false,editable:true,edittype:"select", editrules:{required:true}, 
					   editoptions:{value:"Informatica:Informatica;Textil:Textil;Utiles de escritorio:Utiles de escritorio;Bancos:Bancos;"},searchoptions:{sopt:['cn','eq','ne','lt','le','gt','ge','bw','ew']}},
				   {name:"data[Proveedor][created]",width:55,index:'Proveedor.created',align:'left',sortable:true,editable:false,searchoptions:{sopt:['cn','eq','ne','lt','le','gt','ge','bw','ew']}},
	         	   {name:"data[Proveedor][estado_id]",width:45,index:'Estado.descripcion',align:'left',editable: true,edittype:"select",editrules:{required:true},editoptions:{value:"1:Activo;2:Desactivo"},searchoptions:{sopt:['cn','eq','ne','lt','le','gt','ge','bw','ew']}}               
	           ],
			   pager:$('#proveedores-pager'),
	           rowNum:10,
	           rowList:[10,20,30],
	           mtype: "POST",
	           viewrecords:true,
	           caption:'Proveedores',
	           height:'180',
	           sortname: "Proveedor.razonsocial",
	           editurl: 'proveedores/index'
	                
	       });
	       $('#proveedores').navGrid("#proveedores-pager",{edit:true,add:true,del:true},
				{clearAfterEdit:false,reloadAfterSubmit:true, closeOnEscape:true,afterSubmit:proveedor.afterSubmit},
				{clearAfterAdd:true,reloadAfterSubmit:true, closeOnEscape:true,afterSubmit:proveedor.afterSubmit},
				{width:450,reloadAfterSubmit:true,closeOnEscape:true},{sopt:['cn','eq','ne','lt','le','gt','ge','bw','ew'],multipleSearch:true, closeOnEscape:true}
			);
	       $("#proveedores").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
	       jQuery("#proveedores").jqGrid('setGridWidth',$('#RightPane').width()-50);		   
		},
		afterSubmit: function(response){var respuesta = eval('(' + response.responseText + ')');  return [respuesta.respuesta,respuesta.mensaje];}
};